use std::env;
use std::path::Path;

mod geometry;
use geometry::{output_view, output_scene, output_ini_file};
use geometry::{
    points::Points,
    paths::Paths, /* 线段集 */
    vectors::Vectors,
    boxes::Boxes,
    mesh::Mesh
};

fn main() {
    let args: Vec<String> = env::args().collect();
    if args.len() < 3 {
        panic!("不正确的命令格式！");
    }
    let src_file_name = args[2].as_str();
    let file_path = Path::new(src_file_name);
    let file_name = file_path.file_stem().unwrap().to_str().unwrap();
    // 将间隔线替换为下划线，以防 povray 的变量名不合法
    let good_name = file_name.replace("-", "_");
    let model_name = good_name.as_str();
    let dim = 3;
    output_ini_file(model_name);
    output_view(model_name);
    let sphere;
    match args[1].as_str() {
        "--points" => {
            let mut points: Points<f64> = Points::new(dim, model_name);
            points.load(file_path);
            sphere = points.bounding_sphere();
            points.output_model();
        }
        "--paths" => {
            let mut paths: Paths<f64> = Paths::new(dim, model_name);
            paths.load(file_path);
            sphere = paths.bounding_sphere();
            paths.output_model();
        }
        "--vectors" => {
            let mut vectors: Vectors<f64> = Vectors::new(dim, model_name);
            vectors.load(file_path);
            sphere = vectors.bounding_sphere();
            vectors.output_model();
        }
        "--boxes" => {
            let mut boxes: Boxes<f64> = Boxes::new(dim, model_name);
            boxes.load(file_path);
            sphere = boxes.bounding_sphere();
            boxes.output_model();
        }
        "--mesh" => {
            let mut mesh: Mesh<f64> = Mesh::new(dim, model_name);
            mesh.load(file_path);
            sphere = mesh.bounding_sphere();
            mesh.output_model();
        }
        _ => panic!("不正确的选项！")
    }
    output_scene(&sphere, model_name);
}
